const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
function resolve(dir) {
  return path.join(__dirname, dir);
}
const host = 'http://localhost:8099';
module.exports = {
  lintOnSave: false,
  publicPath: './',
  productionSourceMap: false, //是否保留源文件
  devServer: {
    disableHostCheck: true,
    open: true, //是否打开浏览器
    port: 8088,
    https: false,
    hotOnly: true, //热更新
    proxy: {
      '/': {
        target: host,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/': ''
        }
      }
    }
  },
  chainWebpack: (config) => {
    config.plugins.delete('prefetch');
    config.plugins.delete('preload');
    // 路径别名
    config.resolve.alias
      // 实施包
      .set('@', resolve('./src'))
      .set('@components', resolve('./src/components'))
      .set('@views', resolve('./src/views'))
    // 输出文件加hash
    config.output.filename('[name].[hash].js').end();
    // 打包分析工具
    // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  },
  configureWebpack: config => {
    // 配置webpack 压缩
    config.plugins.push(
      new CompressionWebpackPlugin({
        test: /\.js$|\.html$|\.css$/,
        // 超过4kb压缩
        threshold: 4096,
        // 删除源文件
        deleteOriginalAssets: false
      })
    );
	},
  css:{
    loaderOptions:{
      less:{
        javascriptEnabled:true,//允许链式调用的换行
      }
    }
  },
};
